<template>
<div class="container__">
    <div v-if="addform.type=='11'" class="slw">请选择兴趣爱好，可多选</div>
    <div v-if="addform.type=='11'" class="slebox">
        <div class="item" :class="{'active': item.slec}" v-for="(item, index) in aihao" :key="index" @click="slecte(item)">{{item.name}}</div>
    </div>
    <van-field v-if="addform.type=='2'" :value="addform.nickname" placeholder="请输入名字" :border="false" @change="onChangename" />

    <van-field v-if="addform.type=='3'" :value="addform.age" placeholder="请输入年龄" :border="false" @change="onChangeage" type="number"/>

    <van-field v-if="addform.type=='6'" :maxlength="20" autosize type="textarea" :value="addform.des" placeholder="请输入简介" :border="false" @change="onChangedes" />
    <van-toast id="van-toast" />

    <div class="button" @click="submit">确定</div>
</div>
</template>

<script>
import Toast from '../../../static/dist/toast/toast';
import {
    setnickname
} from '@/api/my'
import {
    setage
} from '@/api/my'
import {
    setbrief
} from '@/api/my'
export default {
    data() {
        return {
            addform: {
                nickname: "",
                age: '',
                des: '',
                type: '',
            },
            aihao: [{
                    name: "书画",
                    id: 1,
                    slec: false
                },
                {
                    name: "乐器",
                    id: 2,
                    slec: false
                },
                {
                    name: "文化课",
                    id: 3,
                    slec: false
                },
                {
                    name: "幼儿教育",
                    id: 4,
                    slec: false
                },
                {
                    name: "留学教育",
                    id: 5,
                    slec: false
                },
            ],

        }
    },
    methods: {
        slecte(item) {
            if (item.slec) return item.slec = false
            item.slec = true
            // console.log(this.aihao)
        },
        editmyinfo() {
           if(this.addform.type=='2'){
               setnickname({nickname:this.addform.nickname}).then(res=>{})
           }
           if(this.addform.type=='3'){
               setage({age:this.addform.age}).then(res=>{})
           }
            if(this.addform.type=='6'){
               setbrief({brief:this.addform.des}).then(res=>{})
           }
        },
        onChangename(e) {
            this.addform.nickname = e.mp.detail
        },
        onChangeage(e) {
            this.addform.age = e.mp.detail
        },
        onChangedes(e) {
            this.addform.des = e.mp.detail
        },
        submit() {
            this.editmyinfo()
            wx.navigateBack({
                delta: 1
            })
        },
        settype() {
            this.addform.type = this.$mp.query.name
        }
    },
    onLoad() {
        Object.assign(this.$data, this.$options.data())
        this.settype()
    },
    onShow() {
        this.settype()

    }
}
</script>

<style lang="scss">
.container__ {
    background-color: #F4F5F5;
    min-height: 100vh;
    font-size: 16px;
    // padding: 15px 0;
    box-sizing: border-box;
    padding: 15px 0 0 0;

    .slw {
        height: 35px;
        background: rgba(244, 245, 245, 1);
        font-size: 14px;
        color: #666666;
        padding: 0 16px;
        box-sizing: border-box;
    }

    .slebox {
        height: 105px;
        background-color: #fff;
        box-sizing: border-box;
        padding: 15px;
        display: flex;
        flex-wrap: wrap;
        // justify-content: space-between;

        .item {
            min-width: 60px;
            height: 25px;
            background: #fff;
            border: 1px solid #666666;
            border-radius: 13px;
            margin-right: 20px;
            font-size: 14px;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .active {
            border: 1px solid rgba(26, 132, 251, 1);
            background: rgba(241, 248, 255, 1);
        }
    }

    input {
        line-height: 40px;
        background: rgba(255, 255, 255, 1);
        padding: 0 17px;
        font-size: 14px;
    }

    .button {
        width: 305px;
        height: 45px;
        background: rgba(26, 132, 251, 1);
        border-radius: 5px;
        color: #fff;
        // font-weight: bold;
        margin: 26px auto;
        line-height: 45px;
        text-align: center;
        font-size: 16px;
    }
}
</style>
